const express = require('express');

var router = express.Router();

//http://localhost:3000/user/42 
// router.get('/:id', (req, res) => {
//   res.send(req.params.id)
// })

//http://localhost:3000/user/66/books/88
router.get('/:id/books/:bookid', (req, res) => {
  res.json({
    id: req.params.id,
    bookid: req.params.bookid
  })
})

// http://localhost:3000/user/flights/LAX-SFO
router.get('/flights/:from-:to', (req, res) => {
  res.send({
    from: req.params.from,
    to: req.params.to,
  })
})

//http://localhost:3000/user/hm.gif?id=1&keyword=china
router.get('/hm.gif', (req, res) => {
  res.send(req.query)
})

//http://localhost:3000/user/add
router.post('/add', (req, res) => {
  res.send({
    code: 1,
    message: '数据获取成功',
    data: req.body
  })
})

module.exports = router;